﻿<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">

    <!-- Top Level Header -->
    <ControlTemplate x:Key="ChromeTopLevelHeaderMenuItemControlTemplate" TargetType="MenuItem">
        <Border>
            <Grid> 
                <Border Name="Border"
                        Background="Transparent"
                        BorderThickness="1">
                    <ContentPresenter Margin="6,3,6,3"                                   
                                      ContentSource="Header"
                                      RecognizesAccessKey="True" />
                </Border>
                <Popup Name="Popup"                       
                       Placement="Bottom"                       
                       IsOpen="{TemplateBinding IsSubmenuOpen}"
                       AllowsTransparency="True" 
                       Focusable="False"
                       VerticalOffset="-1"
                       PopupAnimation="Fade">
                    <Border Name="SubmenuBorder"
                            SnapsToDevicePixels="True"
                            Background="White"
                            BorderBrush="Gray"
                            BorderThickness="1" >
                        <StackPanel IsItemsHost="True" 
                                    KeyboardNavigation.DirectionalNavigation="Cycle" />
                    </Border>
                </Popup>
            </Grid>
        </Border>
        <ControlTemplate.Triggers>
            <Trigger Property="IsSuspendingPopupAnimation" Value="true">
                <Setter TargetName="Popup" Property="PopupAnimation" Value="None"/>
            </Trigger>
            <Trigger Property="IsEnabled" Value="False">
                <Setter Property="Foreground" Value="Gray"/>
            </Trigger>
            <Trigger Property="IsHighlighted" Value="True">
                <Setter TargetName="Border" Property="BorderBrush" Value="Gray" />
                <Setter TargetName="Border" Property="Background" Value="{StaticResource ButtonHotTrackBackgroundBrush}" />
            </Trigger>
        </ControlTemplate.Triggers>
    </ControlTemplate>
    
    <!-- Top Level Item -->
    <ControlTemplate x:Key="ChromeTopLevelItemMenuItemControlTemplate" TargetType="MenuItem">
        <Border Name="Border"
                Background="Transparent">
            <Grid>
                <ContentPresenter Margin="6,3,6,3"
                                  ContentSource="Header"
                                  RecognizesAccessKey="True" />
            </Grid>
        </Border>
        <ControlTemplate.Triggers>
            <Trigger Property="IsEnabled" Value="False">
                <Setter Property="Foreground" Value="Gray"/>
            </Trigger>
            <Trigger Property="IsHighlighted" Value="True">
                <Setter TargetName="Border" Property="Background" Value="{StaticResource ButtonHotTrackBackgroundBrush}" />
            </Trigger>
        </ControlTemplate.Triggers>
    </ControlTemplate>

    <!-- Submenu Item -->
    <ControlTemplate x:Key="ChromeSubItemMenuItemControlTemplate" TargetType="MenuItem">
        <Border Name="Border"
                Background="Transparent"
                Padding="3">
            <Grid>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="Auto" SharedSizeGroup="Icon"/>
                    <ColumnDefinition Width="*" />
                    <ColumnDefinition Width="Auto" SharedSizeGroup="Shortcut"/>
                    <ColumnDefinition Width="13"/>
                </Grid.ColumnDefinitions>
                <ContentPresenter Name="Icon"
                                  Margin="6,0,6,0"
                                  VerticalAlignment="Center"
                                  ContentSource="Icon"/>
                <Border Name="Check"  
                        Width="13" 
                        Height="13" 
                        Visibility="Collapsed"
                        Margin="6,0,6,0" 
                        Background="White"
                        BorderThickness="1"
                        BorderBrush="Gray">
                    <Path Name="CheckMark"
                          Width="7" 
                          Height="7" 
                          Visibility="Hidden" 
                          SnapsToDevicePixels="False" 
                          Stroke="Black"
                          StrokeThickness="2"
                          Data="M 0 0 L 7 7 M 0 7 L 7 0" />
                </Border>
                <ContentPresenter Name="HeaderHost"
                                  Grid.Column="1"
                                  VerticalAlignment="Center"
                                  ContentSource="Header"
                                  RecognizesAccessKey="True"/>
                <TextBlock x:Name="InputGestureText"
                           Grid.Column="2"
                           Text="{TemplateBinding InputGestureText}"
                           Margin="15,2,0,2"
                           DockPanel.Dock="Right" />
            </Grid>
        </Border>
        <ControlTemplate.Triggers>
            <Trigger Property="Icon" Value="{x:Null}">
                <Setter TargetName="Icon" Property="Visibility" Value="Hidden"/>
            </Trigger>
            <Trigger Property="IsChecked" Value="true">
                <Setter TargetName="CheckMark" Property="Visibility" Value="Visible"/>
            </Trigger>
            <Trigger Property="IsCheckable" Value="true">
                <Setter TargetName="Check" Property="Visibility" Value="Visible"/>
                <Setter TargetName="Icon" Property="Visibility" Value="Hidden"/>
            </Trigger>
            <Trigger Property="IsEnabled" Value="false">
                <Setter Property="Foreground" Value="Gray"/>
            </Trigger>
            <Trigger Property="IsHighlighted" Value="True">
                <Setter TargetName="Border" Property="Background" Value="{StaticResource ButtonHotTrackBackgroundBrush}" />
            </Trigger>
        </ControlTemplate.Triggers>
    </ControlTemplate>

    <!-- Submenu Header -->
    <ControlTemplate x:Key="ChromeSubHeaderMenuItemControlTemplate" TargetType="MenuItem">
        <Border Name="Border"
                Background="Transparent"
                Padding="3">
            <Grid>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="Auto" SharedSizeGroup="Icon"/>
                    <ColumnDefinition Width="*" />
                    <ColumnDefinition Width="Auto" SharedSizeGroup="Shortcut"/>
                    <ColumnDefinition Width="13"/>
                </Grid.ColumnDefinitions>
                <ContentPresenter Name="Icon"
                                  Margin="6,0,6,0"
                                  VerticalAlignment="Center"
                                  ContentSource="Icon"/>
                <ContentPresenter Name="HeaderHost"
                                  Grid.Column="1"
                                  VerticalAlignment="Center"
                                  ContentSource="Header"
                                  RecognizesAccessKey="True"/>
                <TextBlock x:Name="InputGestureText"
                           Grid.Column="2"
                           Text="{TemplateBinding InputGestureText}"
                           Margin="15,2,2,2"
                           DockPanel.Dock="Right"/>
                <Path Grid.Column="3"
                      HorizontalAlignment="Center"
                      VerticalAlignment="Center"
                      Data="M 0 0 L 0 7 L 4 3.5 Z" 
                      Fill="Black" />
                <Popup Name="Popup"
                     Placement="Right"
                     HorizontalOffset="-4" 
                     IsOpen="{TemplateBinding IsSubmenuOpen}"
                     AllowsTransparency="True" 
                     Focusable="False"
                     PopupAnimation="Fade">
                    <Border Name="SubmenuBorder"
                            SnapsToDevicePixels="True"
                            Background="White"
                            BorderBrush="Gray"
                            BorderThickness="1" >
                        <StackPanel IsItemsHost="True" 
                                    KeyboardNavigation.DirectionalNavigation="Cycle" />
                    </Border>
                </Popup>
            </Grid>
        </Border>
        <ControlTemplate.Triggers>
            <Trigger Property="Icon" Value="{x:Null}">
                <Setter TargetName="Icon" Property="Visibility" Value="Collapsed"/>
            </Trigger>
            <Trigger Property="IsEnabled" Value="false">
                <Setter Property="Foreground" Value="Gray"/>
            </Trigger>
            <Trigger Property="IsHighlighted" Value="True">
                <Setter TargetName="Border" Property="Background" Value="{StaticResource ButtonHotTrackBackgroundBrush}" />
            </Trigger>
        </ControlTemplate.Triggers>
    </ControlTemplate>

    <!-- MenuItem Style -->
    <Style x:Key="ChromeMenuItemStyle" TargetType="MenuItem">
        <Setter Property="OverridesDefaultStyle" Value="True"/>   
        <Setter Property="ItemContainerStyle" Value="{DynamicResource ChromeMenuItemStyle}" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type Menu}">
                    <Border BorderThickness="1"
                            Background="Transparent">
                        <StackPanel ClipToBounds="True"
                                    Orientation="Horizontal"
                                    IsItemsHost="True" />
                    </Border>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
        <Style.Triggers>
            <Trigger Property="Role" Value="TopLevelHeader">
                <Setter Property="Template" Value="{DynamicResource ChromeTopLevelHeaderMenuItemControlTemplate}"/>
            </Trigger>
            <Trigger Property="Role" Value="TopLevelItem">
                <Setter Property="Template" Value="{DynamicResource ChromeTopLevelItemMenuItemControlTemplate}"/>
            </Trigger>
            <Trigger Property="Role" Value="SubmenuHeader">
                <Setter Property="Template" Value="{DynamicResource ChromeSubHeaderMenuItemControlTemplate}"/>
            </Trigger>
            <Trigger Property="Role" Value="SubmenuItem">
                <Setter Property="Template" Value="{DynamicResource ChromeSubItemMenuItemControlTemplate}"/>
            </Trigger>
        </Style.Triggers>
    </Style>

    <!-- Menu style -->
    <Style x:Key="ChromeMenuStyle" TargetType="{x:Type Menu}">
        <Setter Property="OverridesDefaultStyle" Value="True" />
        <Setter Property="SnapsToDevicePixels" Value="True" />
        <Setter Property="ItemContainerStyle" Value="{DynamicResource ChromeMenuItemStyle}" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type Menu}">
                    <Border BorderThickness="1"
                            Background="Transparent">
                        <StackPanel ClipToBounds="True"
                                    Orientation="Horizontal"
                                    IsItemsHost="True" />
                    </Border>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    <!-- ContextMenu style -->
    <Style x:Key="ChromeContextMenuStyle" TargetType="{x:Type ContextMenu}">
        <Setter Property="SnapsToDevicePixels" Value="True" />
        <Setter Property="OverridesDefaultStyle" Value="True" />
        <Setter Property="Grid.IsSharedSizeScope" Value="true" />
        <Setter Property="ItemContainerStyle" Value="{DynamicResource ChromeMenuItemStyle}" />
        <Setter Property="HasDropShadow" Value="True" />
        <Setter Property="Foreground" Value="Black" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type ContextMenu}">
                    <Border x:Name="Border"
                            Background="White"
                            BorderThickness="1"
                            BorderBrush="Gray">
                        <StackPanel IsItemsHost="True"
                                    KeyboardNavigation.DirectionalNavigation="Cycle" />
                    </Border>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

</ResourceDictionary>